using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.Admin;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;
public class HL_Admin_Admin_AddPageLabel : Admin, IRequiresSessionState
{
	private new int ID = 0;
	private PageLabelBll _pagelabel = null;
	protected TextBox LabelName;
	protected Label LabelNameErr;
	protected TextBox LabelClass;
	protected DropDownList LabelClassSelect;
	protected Label LabelClassErr;
	protected Label temErr;
	protected TextBox TemplateContent;
	protected Button submit;
	protected PageLabelBll pagelabel
	{
		get
		{
			PageLabelBll pagelabel;
			if (this._pagelabel == null)
			{
				this._pagelabel = new PageLabelBll(this.conn);
				pagelabel = this._pagelabel;
			}
			else
			{
				pagelabel = this._pagelabel;
			}
			return pagelabel;
		}
	}
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.admin.CheckAdminPower(1))
		{
			base.WriteLog("View", Language.GetAdminMsg("Log/Access", Fetch.GetID("id").ToString()), "PageLabel");
			base.WriteRightErrMsg();
		}
		if (Fetch.Get("action") == "modify")
		{
			this.ID = Fetch.GetID("id");
		}
		if (!base.IsPostBack)
		{
			if (this.ID > 0)
			{
				this.BingPageLabel(this.ID);
				this.submit.Text = "修 改";
			}
			this.LabelClassSelect.DataSource = this.TypeList();
			this.LabelClassSelect.DataTextField = "Type";
			this.LabelClassSelect.DataValueField = "Type";
			this.LabelClassSelect.DataBind();
			this.LabelClassSelect.Attributes.Add("onchange", "document.getElementById('" + this.LabelClass.ClientID + "').value=this.value");
			this.TemplateContent.Attributes.Add("onmouseup", "dragend();");
			this.TemplateContent.Attributes.Add("onmousemove", "movePoint();");
		}
	}
	protected void onClick_submit(object sender, EventArgs e)
	{
		if (this.LabelName.Text == null || this.LabelName.Text == "")
		{
			this.LabelNameErr.Text = "<font color=red >请输入标签名称！</font>";
		}
		else
		{
			this.LabelNameErr.Text = "";
			if (this.LabelClass.Text == null || this.LabelClass.Text == "")
			{
				this.LabelClassErr.Text = "<font color=red >请输入标签分类，方便查找！</font>";
			}
			else
			{
				this.LabelClassErr.Text = "";
				if (this.TemplateContent.Text == null || this.TemplateContent.Text == "")
				{
					this.temErr.Text = "<font color=red >请输入标签的内容！</font><br/>";
				}
				else
				{
					this.temErr.Text = "";
					if (this.ID > 0)
					{
						this.ModifyPageLabel(this.ID);
					}
					else
					{
						this.AddPageLabel();
					}
				}
			}
		}
	}
	protected void AddPageLabel()
	{
		DataTable pageLabelByName = this.pagelabel.GetPageLabelByName(this.LabelName.Text);
		if (pageLabelByName.Rows.Count > 0)
		{
			this.LabelNameErr.Text = "<font color=red >输入的标签重复！</font>";
		}
		else
		{
			this.LabelNameErr.Text = "";
			this.pagelabel.AddPageLabel(this.LabelName.Text, this.LabelClass.Text, this.TemplateContent.Text);
			this.WriteSuccessMsg("", Language.GetAdminMsg("Common/AddSuccess"), "Admin_PageLable.aspx");
		}
	}
	protected void BingPageLabel(int Id)
	{
		DataTable pageLabelByID = this.pagelabel.GetPageLabelByID(Id);
		if (pageLabelByID.Rows.Count > 0)
		{
			this.LabelName.Text = pageLabelByID.Rows[0]["Name"].ToString();
			this.LabelClass.Text = pageLabelByID.Rows[0]["Type"].ToString();
			this.TemplateContent.Text = pageLabelByID.Rows[0]["Template"].ToString();
		}
		else
		{
			this.WriteErrMsg("", Language.GetAdminMsg("Common/NotData"), "");
		}
	}
	protected void ModifyPageLabel(int Id)
	{
		this.pagelabel.UpdatePageLabel(Id, this.LabelName.Text, this.LabelClass.Text, this.TemplateContent.Text);
		this.WriteSuccessMsg("", Language.GetAdminMsg("Common/EditSuccess"), "Admin_PageLable.aspx");
	}
	protected DataTable TypeList()
	{
		DataTable pageLabelType = this.pagelabel.GetPageLabelType();
		DataTable result;
		if (pageLabelType.Rows.Count > 0)
		{
			result = pageLabelType;
		}
		else
		{
			result = null;
		}
		return result;
	}
}
